Refactor solver core and switch to typed CDDP solutions#159
Merged
Conversation
- Unify ControlConstraint/StateConstraint into BoxConstraint<> template - Add default zero-Hessian implementations in Constraint base class - Extract InteriorPointOptions/MultiShootingOptions base structs in options - Create CDDPSolverBase with template method solve() pattern - Migrate all 4 solvers (CLDDP, LogDDP, IPDDP, MSIPDDP) to use base class - Add DynamicalSystem::makeZeroTensor() helper, update 16 dynamics models - Consolidate 9 finite difference functions into 3 unified templates
Eliminates all std::any_cast usage across 41 files. Solution fields
are now accessed directly (e.g., solution.state_trajectory instead of
std::any_cast<vector<VectorXd>>(solution.at("state_trajectory"))).
Create cddp_example_utils.hpp with extractComponent, makeTimeVector, ensurePlotDir, and makeInitialTrajectory helpers. Apply across all examples to reduce boilerplate data extraction and directory setup.
- Skip convergence check after failed forward pass (prevents false convergence when dJ/dL are zero, which triggered LogDDP's abs check) - Log unconditionally when ALL parallel forward pass threads fail - Add checkEarlyConvergence hook so CLDDP checks inf_du before forward pass - Record iteration history on early convergence path - Fix BoxConstraint::computeViolation double-subtraction of ip_upper_bound_ - Add scale_factor_ to BoxConstraint<Control> control Jacobian for consistency - Unify CDDPSolution::History and IterationHistory into single type - Clean up solve() loop: remove continue, single printIteration call site
Both examples accessed solution.history.objective.back() but history is only populated when return_iteration_info is enabled (default false). Use solution.final_objective instead. Also fix ms-vs-microseconds label.
The template method hardcoded backward pass regularization exhaustion to NotConverged. LogDDP originally treated this as Converged since the barrier-penalized trajectory is typically still usable. Add virtual handleBackwardPassRegularizationLimit hook with LogDDP override.
- Re-add throwing Hessian overrides for PoleConstraint and SecondOrderConeConstraint (nonlinear — zero Hessians are wrong) - Keep zero-return default in base Constraint (correct for linear) - Remove stale #include <any> from cddp_core.hpp - Remove .claude/setting.json from tracked files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the shared CDDP solver internals to reduce duplication across the CLDDP, LogDDP, IPDDP, and MSIPDDP implementations. It also replaces the string-keyed
CDDPSolutionmap with a typed solution struct and updates examples and tests to consume the typed API directly.Changes
CDDPSolverBaseand move the common solve loop, line search handling, derivative precomputation, iteration-history recording, and solution assembly into a shared base implementation.CDDPSolutionmap-of-std::anyresult shape with a typed struct and migrate the in-tree examples and tests to field-based access.cddp_example_utils.hppand reuse it across many examples for initial trajectory setup, directory creation, time vectors, and component extraction.cddp_lti_systemandcddp_hcw, plus the supporting CMake update to compile the new solver-base source.Test Plan
./build/tests/test_logddp_solver./build/tests/test_ipddp_solver./build/tests/test_msipddp_solverHow to Test
./build/tests/test_logddp_solver../build/tests/test_ipddp_solver../build/tests/test_msipddp_solver../build/examples/cddp_lti_systemand./build/examples/cddp_hcwto sanity-check the typed solution access in the updated examples.